package com.lsa.iview.chap1;

public class ArrayQuestions {
	public static void setRowColToZeroIfZero(int[][] matrix) {
		boolean[] rowZeroFlags = new boolean[matrix.length];
		boolean[] colZeroFlags = new boolean[matrix[0].length];
		
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[i].length; j++) {
				if (matrix[i][j] == 0) {
					rowZeroFlags[i] = true;
					colZeroFlags[j] = true;
				}
			}
		}
		
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[i].length; j++) {
				if (rowZeroFlags[i] || colZeroFlags[j]) {
					matrix[i][j] = 0;
				}
			}
		}
	}
}
